package com.nuoniu.sibanyun.service.crm.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.nuoniu.sibanyun.entity.crm.ApprovalProcess;
import com.nuoniu.sibanyun.mapper.crm.ApprovalMapper;
import com.nuoniu.sibanyun.mapper.crm.ApprovalProcessMapper;
import com.nuoniu.sibanyun.service.crm.IApprovalProcessService;
import com.nuoniu.sibanyun.userThread.UserInfo;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 审批流程 服务实现类
 * </p>
 *
 * @author baiqiang
 * @since 2020-06-20
 */
@Service
public class ApprovalProcessServiceImpl extends ServiceImpl<ApprovalProcessMapper, ApprovalProcess> implements IApprovalProcessService {

    @Autowired
    private ApprovalProcessMapper processMapper;
    @Autowired
    private ApprovalMapper approvalMapper;

    @Override
    public Page<ApprovalProcess> pageApprovalProcess(Page pages, ApprovalProcess process) {
        UserInfo userInfo = UserThreadLocal.get();
        ApprovalProcess approvalProcess = new ApprovalProcess();
        QueryWrapper<ApprovalProcess> queryWrapper = new QueryWrapper<>(approvalProcess);
        queryWrapper.eq("company_id", userInfo.getCompanyId());
        queryWrapper.eq("status", 0);
        if(StringUtils.isNotBlank(process.getProcessName())){
            queryWrapper.like("process_name", process.getProcessName());
        }
        queryWrapper.orderByDesc("create_date");
        Page<ApprovalProcess> page = page(pages, queryWrapper);
        return page;
    }

    @Override
    public void updateUserName(Long id, String realName) {
        processMapper.updateUserName(id.toString(), realName);
        approvalMapper.updateUserName(id.toString(), realName);
    }
}
